package com.studyv3.test.controller.stock;


import com.studyv3.common.annotation.Log;
import com.studyv3.common.core.controller.BaseController;
import com.studyv3.common.core.domain.AjaxResult;
import com.studyv3.common.core.page.TableDataInfo;
import com.studyv3.common.enums.BusinessType;
import com.studyv3.common.utils.poi.ExcelUtil;
import com.studyv3.test.domain.Stock;
import com.studyv3.test.service.IStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * lb_库存表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-05-06
 */
@RestController
@RequestMapping("/stock/")
public class StockController  extends BaseController {
    @Autowired
    IStockService stockService;

    /**
     * 按商品、批次获取库存列表,按批次分类
     */
    @GetMapping("list")
    public TableDataInfo list(Stock stock) {
        startPage();
        List<Stock> list = stockService.selectStock(stock);
        return getDataTable(list);
    }

    @GetMapping("listall")
    public AjaxResult listall(Stock stock) {
        List<Stock> list = stockService.selectStock(stock);
        return AjaxResult.success().put(
                "data", list
        );
    }

    @Log(title = "库存明细", businessType = BusinessType.EXPORT)
//    @PreAuthorize("@ss.hasPermi('system:post:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Stock post)
    {
        List<Stock> list = stockService.selectStock(post);
        ExcelUtil<Stock> util = new ExcelUtil<Stock>(Stock.class);
        util.exportExcel(response, list, "岗位数据");
    }


    /**
     * 按商品获取库存列表,及预警值分页
     */
    @GetMapping("listnobatch")
    public TableDataInfo listnobatch(Stock stock) {
        startPage();
        List<Stock> list = stockService.selectStockNoBatch(stock);
        return getDataTable(list);
    }

    /**
     * 按全部商品及库存,预警值
     */
    @GetMapping("listnobatchall")
    public AjaxResult listnobatchall(Stock stock) {
        AjaxResult ajax = AjaxResult.success();
        List<Stock> list = stockService.selectStockNoBatch(stock);
        ajax.put("apply",list);
        return ajax;
    }
}
